﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

using System.Data.Linq;
using System.Data.Linq.Mapping;
using Microsoft.Phone.Data.Linq;
using Microsoft.Phone.Data.Linq.Mapping;
using System.Collections.ObjectModel;
using System.Text;

namespace MetroWashroom
{
    public partial class Seach : PhoneApplicationPage
    {
       // public ObservableCollection<SeachStaion> seachStaionBind;

        public Seach()
        {
            InitializeComponent();
        }

        private void btSeach_Click(object sender, RoutedEventArgs e)
        {
            string stationName=tbStationName.Text;
            if(string.IsNullOrEmpty(stationName))
            {
                MessageBox.Show("请输入站名");
                return;
            }
            IEnumerable<StationTable> seachTable = from s in App.AppMertroDB.StationTable
                                                   where s.Sation.Contains(stationName)
                                                   select s;
            List<string> seachStationList = new List<string>();
            foreach(StationTable stationSingle in seachTable)
            {
                string message = "(" + IntNumToLineString(stationSingle.LineNum) + ")"+stationSingle.Sation+"["+OutOrIner(stationSingle.IsInner)+"]："+stationSingle.Descible;
                seachStationList.Add(message);
            }
            if (seachStationList.Count == 0)
                seachStationList.Add("抱歉，没有这个站点的数据");
            seachListBox.DataContext = seachStationList;
        }

        private string IntNumToLineString(int? num)
        {
            switch (num)
            {
                case 1: return "一号线";
                case 2: return "二号线";
                case 3: return "三号线";
                case 4: return "四号线";
                case 5: return "五号线";
                case 8: return "八号线";
                case 9: return "广佛线";
                case 10: return "APM线";
                default: return "";
            }
        }

        private string OutOrIner(bool? flag)
        {
            return flag == false ? "站内" : "站外";
        }

        private void tbStationName_GotFocus(object sender, RoutedEventArgs e)
        {
            tbStationName.Text = "";
        }

        private void tbStationName_LostFocus(object sender, RoutedEventArgs e)
        {
            //tbStationName.Text = "请输入站名：";
        }
    }
}